# -*- encoding: utf-8 -*-
"""
File Name: alarm_manager
Description:
Author : 'lirui'
date: 2024/2/7
Contact: marjey_lee@163.com
Change Activity:
2024/2/7:
"""

import ll
from projects.monitoring.alarm_manager.modules.subscribers.subscriber_factory import SubscriberFactory
from projects.monitoring.common.cfg.redis import REDIS_PUBLISHER_CONFIG


class AlarmManager:
    def __init__(self, ):
        super().__init__()
        self._health_check = 1
        self.subscribers = self._build_subscribers()

    def subscribe(self):
        for s in self.subscribers:
            s.subscribe()

    def health_check(self):
        return self._health_check

    @staticmethod
    def _build_subscribers():
        """
        build subscribers.
        """
        subs = []
        for _, info in REDIS_PUBLISHER_CONFIG.items():
            build_fun = SubscriberFactory.create(
                info['channel']
            )
            ll.get_logger().info(f'Build subscriber {build_fun}')
            sub = build_fun(
                host=info['ip'],
                port=info['port'],
                channel=info['channel']
            )
            subs.append(sub)
        return subs
